using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;

/**魔法子弹 */
public class StaffBullet : BulletBase
{
    /**偏移x */
    public float offsetX;
    
    /**偏移y */
    public float offsetY;

    /**子弹数据 */
    private BulletData _data;
    
    // Start is called before the first frame update
    void Start()
    {
        transform.position += new Vector3(offsetX, offsetY, 0.0f);
    }

    // Update is called once per frame
    void Update()
    {
        var movement = new Vector3(_data.speed * Time.deltaTime, 0, 0);
        transform.position += movement;

        if (_data.speed < 0 && transform.position.x < _data.endPos.x)
        {
            Destroy(gameObject);
        } 
        else if (_data.speed > 0 && transform.position.x > _data.endPos.x)
        {
            Destroy(gameObject);
        }
    }

    /**初始化数据 */
    public override void InitData(BulletData data)
    {
        _data = data;
    }

    private void OnCollisionEnter2D(Collision2D col)
    {
        switch(col.gameObject.tag)
        {
            case "Bat":
            case "Plant":
            case "Trunk":
                Destroy(col.gameObject);
                Destroy(gameObject);
                return;
        }
    }
}
